; (define (empty-env) 
;     (list ’empty-env)
; )


; (define (extend-env var val env)
;     (list ’extend-env var val env)
; )


; (define (apply-env env search-var)
;     (cond
;         ((eqv? (car env) ’empty-env)
;             (report-no-binding-found search-var)
;         )
;         ((eqv? (car env) ’extend-env)
;             (let ((saved-var (cadr env))
;                     (saved-val (caddr env))
;                     (saved-env (cadddr env)))
;                 (if (eqv? search-var saved-var)
;                     saved-val
;                     (apply-env saved-env search-var)
;                 )
;             )
;         )
;         (else
;             (report-invalid-env env)
;         )
;     )
; )


(define (report-no-binding-found search-var)
    (eopl:error ’apply-env "No binding for ~s" search-var)
)


(define (report-invalid-env env)
    (eopl:error ’apply-env "Bad environment: ~s" env)
)


(define (empty-env1) 
    `()
)


(define (extend-env1 var val env)
    (cons var
        (cons val env)
    )
)


(define (apply-env1 env search-var)
    (if (eqv? env `empty-env1)
        (report-no-binding-found)
        (let
            (
                (saved-var (car env))
                (saved-val (cadr env))
                (saved-env (caddr env))
            )
            (if (eqv? search-var saved-var)
                saved-val
                (apply-env1 saved-env search-var)
            )
        )
    )
)


(define (empty-env2) 
    `()
)


(define (extend-env2 var val env)
    (cons 
        (list var val) 
        env
    )
)


(define (apply-env2 env search-var)
    (if (eqv? env `empty-env2)
        (report-no-binding-found)
        (let
            (
                (saved-var (caar env))
                (saved-val (cadar env))
                (saved-env (cdr env))
            )
            (if (eqv? search-var saved-var)
                saved-val
                (apply-env2 saved-env search-var)
            )
        )
    )
)


(define (empty-env3) 
    `()
)


(define (extend-env3 var val env)
    (if (null? env)
        (list (list var) (list val))
        (cons
            (cons var (car env))
            (cons val (cdr env))
        )
    )
)


(define (apply-env3 env search-var)
    (if (eqv? env `empty-env3)
        (report-no-binding-found)
        (let
            (
                (saved-var (caar env))
                (saved-val (caadr env))
                (saved-env (cons 
                    (cdar env)
                    (cdadr env))
                )
            )
            (if (eqv? search-var saved-var)
                saved-val
                (apply-env3 saved-env search-var)
            )
        )
    )
)
